/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package entities1;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author takamflore
 */
@Entity
@Table(catalog = "meteoCalDB", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Event.findAll", query = "SELECT e FROM Event e"),
    @NamedQuery(name = "Event.findById", query = "SELECT e FROM Event e WHERE e.id = :id"),
    @NamedQuery(name = "Event.findByNameEvent", query = "SELECT e FROM Event e WHERE e.nameEvent = :nameEvent"),
    @NamedQuery(name = "Event.findByDateEvent", query = "SELECT e FROM Event e WHERE e.dateEvent = :dateEvent"),
    @NamedQuery(name = "Event.findByType", query = "SELECT e FROM Event e WHERE e.type = :type"),
    @NamedQuery(name = "Event.findByAddress", query = "SELECT e FROM Event e WHERE e.address = :address"),
    @NamedQuery(name = "Event.findByDescription", query = "SELECT e FROM Event e WHERE e.description = :description"),
    @NamedQuery(name = "Event.findByHour", query = "SELECT e FROM Event e WHERE e.hour = :hour")})
public class Event implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(nullable = false)
    private Integer id;
    @Basic(optional = false)
    @NotNull(message = "May not be empty")
    @Size(min = 1, max = 45)
    @Column(nullable = false, length = 45)
    private String nameEvent;
    @Basic(optional = false)
    @NotNull(message = "May not be empty")
    @Column(nullable = false)
    @Temporal(TemporalType.DATE)
    private Date dateEvent;
    @Basic(optional = false)
    @NotNull(message = "May not be empty")
    @Size(min = 1, max = 8)
    @Column(nullable = false, length = 8)
    private String type;
    @Basic(optional = false)
    @NotNull(message = "May not be empty")
    @Size(min = 1, max = 45)
    @Column(nullable = false, length = 45)
    private String address;
    @Basic(optional = false)
    @NotNull(message = "May not be empty")
    @Size(min = 1, max = 60)
    @Column(nullable = false, length = 60)
    private String description;
    @Basic(optional = false)
    @NotNull(message = "May not be empty")
    @Column(nullable = false)
    @Temporal(TemporalType.TIME)
    private Date hour;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "event")
    private Collection<Invited> invitedCollection;
    @JoinColumn(name = "Weather", referencedColumnName = "ID", nullable = false)
    @ManyToOne(optional = false)
    private WeatherInformation weather;
    @JoinColumn(name = "Organizer", referencedColumnName = "ID", nullable = false)
    @ManyToOne(optional = false)
    private Users organizer;
    @JoinColumn(name = "Invited", referencedColumnName = "ID", nullable = false)
    @ManyToOne(optional = false)
    private Users invited;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "event")
    private Collection<InvitationRequest> invitationRequestCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "event")
    private Collection<Notify> notifyCollection;

    public Event() {
    }

    public Event(Integer id) {
        this.id = id;
    }

    public Event(Integer id, String nameEvent, Date dateEvent, String type, String address, String description, Date hour ) {
        this.id = id;
        this.nameEvent = nameEvent;
        this.dateEvent = dateEvent;
        this.type = type;
        this.address = address;
        this.description = description;
        this.hour = hour;
       
    }
// new event
    
    public Event( String nameEvent, Date dateEvent, String type, String address, String description, Date hour,int weather,int organizer, List<Integer> invited) {
        this.nameEvent = nameEvent;
        this.dateEvent = dateEvent;
        this.type = type;
        this.address = address;
        this.description = description;
        this.hour = hour;
        this.weather.setId(weather);
        this.organizer.setId(organizer);
       /* 
        for(int i=0,i=ist){
            this.
        }*/
        
    }
    
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getNameEvent() {
        return nameEvent;
    }

    public void setNameEvent(String nameEvent) {
        this.nameEvent = nameEvent;
    }

    public Date getDateEvent() {
        return dateEvent;
    }

   public void setDateEvent(Date date) {
        
        this.dateEvent = date;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Date getHour() {
        return hour;
    }

    public void setHour(Date hour) {
        this.hour = hour;
    }

    @XmlTransient
    public Collection<Invited> getInvitedCollection() {
        return invitedCollection;
    }

    public void setInvitedCollection(Collection<Invited> invitedCollection) {
        this.invitedCollection = invitedCollection;
    }

    public WeatherInformation getWeather() {
        return weather;
    }

    public void setWeather(WeatherInformation weather) {
        this.weather = weather;
    }

    public Users getOrganizer() {
        return organizer;
    }

    public void setOrganizer(Users organizer) {
        this.organizer = organizer;
    }

    public Users getInvited() {
        return invited;
    }

    public void setInvited(Users invited) {
        this.invited = invited;
    }

    @XmlTransient
    public Collection<InvitationRequest> getInvitationRequestCollection() {
        return invitationRequestCollection;
    }

    public void setInvitationRequestCollection(Collection<InvitationRequest> invitationRequestCollection) {
        this.invitationRequestCollection = invitationRequestCollection;
    }

    @XmlTransient
    public Collection<Notify> getNotifyCollection() {
        return notifyCollection;
    }

    public void setNotifyCollection(Collection<Notify> notifyCollection) {
        this.notifyCollection = notifyCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Event)) {
            return false;
        }
        Event other = (Event) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entities.Event[ id=" + id + " ]";
    }
    
}
